package org.tigris.atlas.examples.service;

import java.util.Iterator;

import org.tigris.atlas.examples.service.delegate.EntityMaintenanceServiceDelegate;
import org.tigris.atlas.examples.service.delegate.ServiceDelegateFactory;
import org.tigris.atlas.examples.service.delegate.TxnTestServiceDelegate;
import org.tigris.atlas.examples.transfer.TxnTestDomain;
import org.tigris.atlas.examples.transfer.TxnTestDomainPK;

import junit.framework.TestCase;

public class TestTxnService extends TestCase {

	TxnTestServiceDelegate delegate;

	protected void setUp() throws Exception {
		super.setUp();
				
		delegate = ServiceDelegateFactory.createTxnTestServiceDelegate();
	}
	
	protected void tearDown() throws Exception {
		EntityMaintenanceServiceDelegate emsd = ServiceDelegateFactory.createEntityMaintenanceServiceDelegate();
		Iterator i = delegate.selectAllRecords().getTxnTestDomains().iterator();		
		while( i.hasNext() ) {
			TxnTestDomain entity = (TxnTestDomain) i.next();
			TxnTestDomainPK pk = entity.getTxnTestDomainPK();
			emsd.delete( pk );
		}
		
		super.tearDown();
	}
	
	public void testServiceFailure1() {
		assertEquals(0, delegate.selectAllRecords().getTxnTestDomains().size());
		
		delegate.createOneFailOne();
		
		assertEquals(1, delegate.selectAllRecords().getTxnTestDomains().size());
	}
	
	public void testServiceSuccess() {
		assertEquals(0, delegate.selectAllRecords().getTxnTestDomains().size());
		
		delegate.createTwo();
		
		assertEquals(2, delegate.selectAllRecords().getTxnTestDomains().size());
	}
	
}
